package com.itehima.text;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Demo03 {
    public static void main(String[] args) {

        //定义两个集合，一个存男，一个存女
        ArrayList<String> manlist=new ArrayList<>();
        ArrayList<String> womanlist=new ArrayList<>();

        //添加数据
        Collections.addAll(manlist, "蔡坤坤,24", "叶齁咸,23", "刘不甜,22", "吴签,24", "谷嘉,30", "肖梁梁,27");
        Collections.addAll(womanlist, "赵小颖,35", "杨颖,36", "高元元,43", "张天天,31", "刘诗,35", "杨小幂,33");

        //筛选数据
        Stream<String> stream1 = manlist.stream().filter(s -> s.split(",")[0].length() == 3).limit(3);
        Stream<String> stream2 = womanlist.stream().filter(s -> s.split(",")[0].startsWith("杨")).skip(1);

        //将两个stream流合并到一起
        Stream<String> stream3 = Stream.concat(stream1, stream2);

        //实现类型转换，将合并以后的数据流转换为自定义Actor对象
       //详细版本

        Stream<Actor> newmap1 = stream3.map(new Function<String, Actor>() {
            @Override
            public Actor apply(String s) {
                String name = s.split(",")[0];//姓名
                int age = Integer.parseInt(s.split(",")[1]);//年龄从字符串转换为整形
                return new Actor(name, age);
            }
        });
        System.out.println(newmap1);
        List<Actor> newlist1 = newmap1.collect(Collectors.toList());
        System.out.println(newlist1);


//        List<Actor> list1 = stream3.map(s -> new Actor(s.split(",")[0], Integer.parseInt(s.split(",")[1])))
//                .collect(Collectors.toList());
//        System.out.println(list1);


    }
}
